home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Link.cpp
-
- Contains: Implementation of ODLink class
-
- Owned by: Craig Carper
-
- Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <4> 5/24/96 jpa 1246074: SOM_CATCH --> SOM_TRY..SOM_ENDTRY
- <3> 3/19/96 TJ Included TempObj.h
- <2> 3/15/96 CC 1331422: CreateLinkEdition & GetLinkEdition
- return an ODByteArray instead of an
- uncopied handle.
-
- To Do:
- In Progress:
-
- */
-
- #define VARIABLE_MACROS
-
- #define ODLink_Class_Source
- #include <Link.xih>
-
- #ifndef _LINKDLGS_
- #include <LinkDlgs.h>
- #endif
-
- #ifndef _EXCEPT_
- #include <Except.h>
- #endif
-
- #ifndef _ODMEMORY_
- #include <ODMemory.h>
- #endif
-
- #ifndef _CONSTDEF_
- #include <ConstDef.h>
- #endif
-
- #ifndef SOM_ODLinkSource_xh
- #include <LinkSrc.xh>
- #endif
-
- #ifndef SOM_ODLinkManager_xh
- #include <LinkMgr.xh>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include <ODCtr.xh>
- #endif
-
- #ifndef SOM_ODDocument_xh
- #include <Document.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODStorageSystem_xh
- #include <ODStor.xh>
- #endif
-
- #ifndef _PLFMFILE_
- #include <PlfmFile.h>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef _ODDEBUG_
- #include <ODDebug.h>
- #endif
-
- #ifndef _BARRAY_
- #include <BArray.h>
- #endif
-
- #ifndef _STDTYPIO_
- #include <StdTypIO.h>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdDefs_defined
- #include <StdDefs.xh>
- #endif
-
- #ifndef _TEMPOBJ_
- #include "TempObj.h"
- #endif
-
- #if ODDebug
- #define ODDebugLink 1
- #else
- #define ODDebugLink 0
- #endif
-
- #pragma segment ODLink
-
- //==============================================================================
- // Local Functions
- //==============================================================================
-
- static ODBoolean IsTopDraft(Environment* ev, ODDraft* draft);
-
- //------------------------------------------------------------------------------
- // IsTopDraft
- //------------------------------------------------------------------------------
-
- static ODBoolean IsTopDraft(Environment* ev, ODDraft* draft)
- {
- #if ODDebugLink
- somPrintf("IsTopDraft: draft refcount is %d\n", draft->GetRefCount(ev));
- #endif
-
- return !(draft->GetDocument(ev)->Exists(ev, kODNULLID, draft, kODPosFirstAbove));
- }
-
- //==============================================================================
- // ODLink
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // ODLink: somUninit
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinksomUninit(ODLink *somSelf)
- {
- /* ODLinkData *somThis = ODLinkGetData(somSelf); */
- ODLinkMethodDebug("ODLink","somUninit");
-
- parent_somUninit(somSelf);
- }
-
- //------------------------------------------------------------------------------
- // ODLink: InitLink
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkInitLink(ODLink *somSelf, Environment *ev,
- ODStorageUnit* storageUnit)
- {
- ODLinkData *somThis = ODLinkGetData(somSelf);
- ODLinkMethodDebug("ODLink","InitLink");
-
- SOM_TRY
-
- /* Moved from somInit. SOM itself sets fields to zero
- _fSection = (SectionHandle) kODNULL;
- _fDirty = kODFalse;
- */
- somSelf->InitBaseLink(ev, storageUnit);
-
- somSelf->SetLinkDirty(ev);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLink: InitLinkFromStorage
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkInitLinkFromStorage(ODLink *somSelf, Environment *ev,
- ODStorageUnit* storageUnit)
- {
- ODLinkData *somThis = ODLinkGetData(somSelf);
- ODLinkMethodDebug("ODLink","InitLinkFromStorage");
-
- SOM_TRY
-
- /* Moved from somInit. SOM itself sets fields to zero
- _fSection = (SectionHandle) kODNULL;
- _fDirty = kODFalse;
- */
- somSelf->InitBaseLinkFromStorage(ev, storageUnit);
-
- if (ODSUExistsThenFocus(ev, storageUnit, kODPropLinkSection, kODApplesect))
- {
- const int sectionRecordSize = sizeof(SectionRecord);
-
- if ( storageUnit->GetSize(ev) != sectionRecordSize )
- THROW(kODErrCorruptLink);
-
- AliasHandle alias = kODNULL;
- ODVolatile(alias);
-
- TRY
- _fSection = (SectionHandle) ODNewHandle(sectionRecordSize);
- ODValue theSectionPtr = ODLockHandle((ODHandle) _fSection);
- StorageUnitGetValue(storageUnit, ev, sectionRecordSize, theSectionPtr);
- ODUnlockHandle((ODHandle) _fSection);
-
- if ( (**_fSection).kind != stPublisher )
- THROW(kODErrCorruptLink);
-
- storageUnit->Focus(ev, kODPropEditionAlias, kODPosUndefined, kODApplealis, (ODValueIndex)0, kODPosUndefined);
- ODULong size = storageUnit->GetSize(ev);
-
- if ( size < sizeof(AliasRecord) )
- THROW(kODErrCorruptLink);
-
- alias = (AliasHandle) ODNewHandle(size);
- ODValue theAliasPtr = ODLockHandle((ODHandle) alias);
- StorageUnitGetValue(storageUnit, ev, size, theAliasPtr);
- ODUnlockHandle((ODHandle) alias);
- CATCH_ALL
- ODDisposeHandle((ODHandle) _fSection);
- _fSection = (SectionHandle) kODNULL;
- ODDisposeHandle((ODHandle) alias);
- RERAISE;
- ENDTRY
-
- (**_fSection).alias = alias;
- (**_fSection).refCon = (long) somSelf;
-
- if ( IsTopDraft(ev, storageUnit->GetDraft(ev)) )
- {
- if ( IsRegisteredSection(_fSection) != noErr )
- {
- ODBoolean aliasWasUpdated;
-
- ODContainer* container = storageUnit->GetDraft(ev)->GetDocument(ev)->GetContainer(ev);;
- ODFileSpec documentSpec = GetODFileSpecFromContainer(ev, container);
-
- OSErr error = RegisterSection(&documentSpec, _fSection, &aliasWasUpdated);
-
- // For now, ignore any error returned by RegisterSection. The most likely errors are:
- // multiplePublisherWrn = -460, A Publisher is already registered for that container
- // containerNotFoundWrn = -461, Could not find editionContainer at this time
- // containerAlreadyOpenWrn = -462, Container already opened by this section
- // notThePublisherWrn = -463, Not the first registered publisher for that container
-
- if ( IsRegisteredSection(_fSection) == noErr )
- somSelf->Acquire(ev); // Link must not be deleted untill its section is unregistered!
- }
- }
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLink: Release (OVERRIDE)
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkRelease(ODLink *somSelf, Environment *ev)
- {
- ODLinkData *somThis = ODLinkGetData(somSelf);
- ODLinkMethodDebug("ODLink","Release");
-
- SOM_TRY
-
- parent_Release(somSelf, ev);
-
- #if ODDebugLink
- somPrintf("ODLink %d::Release: Ref count is %d\n", somSelf->GetID(ev), somSelf->GetRefCount(ev));
- #endif
-
- if (somSelf->GetRefCount(ev) == 0)
- somSelf->GetStorageUnit(ev)->GetDraft(ev)->ReleaseLink(ev, somSelf);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLink: Externalize (OVERRIDE)
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkExternalize(ODLink *somSelf, Environment *ev)
- {
- ODLinkData *somThis = ODLinkGetData(somSelf);
- ODLinkMethodDebug("ODLink","Externalize");
-
- SOM_TRY
-
- parent_Externalize(somSelf,ev);
-
- ODStorageUnit* su = somSelf->GetStorageUnit(ev);
-
- if ( _fDirty )
- {
- if ( _fSection == (SectionHandle) kODNULL )
- {
- ODSURemoveProperty(ev, su, kODPropLinkSection);
- ODSURemoveProperty(ev, su, kODPropEditionAlias);
- }
- else
- {
- SectionPtr theSectionPtr = (SectionPtr) ODLockHandle((ODHandle) _fSection);
-
- ODSUForceFocus(ev, su, kODPropLinkSection, kODApplesect);
- StorageUnitSetValue(su, ev, ODGetHandleSize((ODHandle) _fSection), (ODValue) theSectionPtr);
-
- ODValue theAliasPtr = ODLockHandle((ODHandle) theSectionPtr->alias);
- ODSUForceFocus(ev, su, kODPropEditionAlias, kODApplealis);
- StorageUnitSetValue(su, ev, ODGetHandleSize((ODHandle) theSectionPtr->alias), theAliasPtr);
-
- ODUnlockHandle((ODHandle) theSectionPtr->alias);
- ODUnlockHandle((ODHandle) _fSection);
- }
- _fDirty = kODFalse;
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLink: CloneInto (OVERRIDE)
- //------------------------------------------------------------------------------
- // We don't clone the cross-document link info, so a second publisher can't be created.
- // This depends on this method being called rather than ODStorageUnit::CloneInto().
- // Currently, all link objects are internalized when a draft is opened, so this is true.
-
- SOM_Scope void SOMLINK ODLinkCloneInto(ODLink *somSelf, Environment *ev,
- ODDraftKey key,
- ODStorageUnit* toSU,
- ODFrame* scopeFrame)
- {
- ODLinkData *somThis = ODLinkGetData(somSelf);
- ODLinkMethodDebug("ODLink","CloneInto");
-
- SOM_TRY
-
- // If one of our properties already exists, this object has been cloned already
- if ( toSU->Exists(ev, kODPropLinkSection, kODApplesect, 0) )
- return;
-
- parent_CloneInto(somSelf, ev, key, toSU, scopeFrame);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLink: ReleaseAll (OVERRIDE)
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkReleaseAll(ODLink *somSelf, Environment *ev)
- {
- ODLinkData *somThis = ODLinkGetData(somSelf);
- ODLinkMethodDebug("ODLink","ReleaseAll");
-
- SOM_TRY
-
- parent_ReleaseAll(somSelf,ev);
-
- if ( _fSection != (SectionHandle) kODNULL )
- {
- if ( IsTopDraft(ev, somSelf->GetStorageUnit(ev)->GetDraft(ev)) )
- {
- if ( IsRegisteredSection(_fSection) == noErr )
- {
- OSErr error = UnRegisterSection(_fSection);
- somSelf->Release(ev); // RefCount incremented when section was registered
- }
- }
-
- ODDisposeHandle((ODHandle) (**_fSection).alias);
- ODDisposeHandle((ODHandle) _fSection);
- _fSection = (SectionHandle) kODNULL;
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODBaseLink: UpdateDependents (OVERRIDE)
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkUpdateDependents(ODLink *somSelf, Environment *ev)
- {
- ODLinkData *somThis = ODLinkGetData(somSelf);
- ODLinkMethodDebug("ODLink","UpdateDependents");
-
- SOM_TRY
-
- parent_UpdateDependents(somSelf, ev);
-
- if ( (_fSection != (SectionHandle) kODNULL) )
- {
- ODBoolean autoUpdate = somSelf->GetLinkSource(ev)->IsAutoUpdate(ev);
- if ( autoUpdate )
- {
- ODLinkManager* linkManager = somSelf->GetStorageUnit(ev)->GetSession(ev)->GetLinkManager(ev);
- linkManager->ExportOnSave(ev, somSelf, kODTrue);
- }
- else
- {
- ODLinkKey key;
- ODVolatile(key);
- if ( somSelf->Lock(ev, 0, &key) )
- {
- TRY
- somSelf->UpdateLinkEdition(ev, key);
- CATCH_ALL
- somSelf->Unlock(ev, key);
- RERAISE;
- ENDTRY
- somSelf->Unlock(ev, key);
- }
- }
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLink::ShowLinkDestinationInfo (OVERRIDE)
- //------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK ODLinkShowLinkDestinationInfo(ODLink *somSelf, Environment *ev,
- ODFacet* facet,
- ODLinkInfo* info,
- ODBoolean changesAllowed,
- ODLinkInfoResult* infoResult)
- {
- ODLinkData *somThis = ODLinkGetData(somSelf);
- ODLinkMethodDebug("ODLink","ShowLinkDestinationInfo");
-
- SOM_TRY
-
- ODLinkSource* linkSource = somSelf->GetLinkSource(ev);
-
- ODError error = linkSource->GetStatus(ev);
-
- if ( error )
- ShowLinkStatusAlert(error);
-
- return parent_ShowLinkDestinationInfo(somSelf, ev, facet, info, changesAllowed, infoResult);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- return kODFalse;
- }
-
- //------------------------------------------------------------------------------
- // ODLink: SetLinkDirty
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkSetLinkDirty(ODLink *somSelf, Environment *ev)
- {
- ODLinkData *somThis = ODLinkGetData(somSelf);
- ODLinkMethodDebug("ODLink","SetLinkDirty");
-
- SOM_TRY
- _fDirty = kODTrue;
-
- ODDraft* draft = somSelf->GetStorageUnit(ev)->GetDraft(ev);
- if ( draft->GetPermissions(ev) != kODDPReadOnly )
- draft->SetChangedFromPrev(ev);
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLink: CreateLinkEdition
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkCreateLinkEdition(ODLink *somSelf, Environment *ev,
- EditionContainerSpec editionContainer,
- ODFileSpec* documentSpec,
- ODULong sectionID,
- ODLinkKey key,
- ODByteArray* aliasData)
- {
- ODLinkData *somThis = ODLinkGetData(somSelf);
- ODLinkMethodDebug("ODLink","CreateLinkEdition");
-
- OSErr error;
- OSErr createError = mFulErr; // Anything but noErr
- SectionHandle tempSection = kODNULL;
-
- ODVolatile(createError);
- ODVolatile(tempSection);
- ODVolatile(editionContainer);
-
- SOM_TRY
-
- somSelf->KeyValid(ev, key);
-
- // Should throw kODErrCannotCreateLink if linkSource imports
-
- if ( _fSection != kODNULL)
- THROW(kODErrLinkAlreadyExported); // Internal error
-
- FInfo documentFInfo;
- error = FSpGetFInfo((FSSpecPtr) documentSpec, &documentFInfo);
- THROW_IF_ERROR(error);
-
- createError = CreateEditionContainerFile(&editionContainer.theFile,
- documentFInfo.fdCreator, editionContainer.theFileScript);
- THROW_IF_ERROR(createError);
-
- error = NewSection(&editionContainer, (FSSpecPtr) documentSpec, stPublisher, sectionID, pumOnSave, &tempSection);
- if ( (error != noErr) &&
- (error != multiplePublisherWrn) &&
- (error != notThePublisherWrn) )
- {
- THROW(error);
- }
-
- (**tempSection).mdDate = (TimeStamp) somSelf->GetChangeTime(ev);
- (**tempSection).refCon = (long) somSelf;
-
- somSelf->WriteLinkEdition(ev, tempSection, (FSSpecPtr) documentSpec, key);
-
- // Edition file was successfully created and written, so add section to persistent state.
- // This Link must not be deleted until its section is unregistered!
- _fSection = tempSection;
- somSelf->Acquire(ev);
-
- somSelf->SetLinkDirty(ev);
-
- TempODHandleLock aHandle((ODHandle) (**_fSection).alias);
- if ( (ODHandle) aHandle )
- *aliasData = CreateByteArrayStruct(*(ODHandle) aHandle, ODGetHandleSize(aHandle));
-
- SOM_CATCH_ALL
-
- if ( createError == noErr )
- DeleteEditionContainerFile(&editionContainer.theFile);
-
- if ( tempSection )
- {
- UnRegisterSection(tempSection);
- ODDisposeHandle((ODHandle) (**tempSection).alias);
- ODDisposeHandle((ODHandle) tempSection);
- }
-
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLink: GetLinkEdition
- //------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK ODLinkGetLinkEdition(ODLink *somSelf, Environment *ev,
- ODLinkKey key,
- ODByteArray* aliasData)
- {
- ODLinkData *somThis = ODLinkGetData(somSelf);
- ODLinkMethodDebug("ODLink","GetLinkEdition");
-
- ODBoolean result = kODFalse;
-
- SOM_TRY
-
- somSelf->KeyValid(ev, key);
-
- if ( _fSection != (SectionHandle) kODNULL )
- {
- TempODHandleLock aHandle((ODHandle) (**_fSection).alias);
- if ( (ODHandle) aHandle )
- {
- *aliasData = CreateByteArrayStruct(*(ODHandle) aHandle, ODGetHandleSize(aHandle));
- result = kODTrue;
- }
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // ODLink: DeleteLinkEdition
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkDeleteLinkEdition(ODLink *somSelf, Environment *ev,
- ODLinkKey key)
- {
- ODLinkData *somThis = ODLinkGetData(somSelf);
- ODLinkMethodDebug("ODLink","DeleteLinkEdition");
-
- SOM_TRY
-
- somSelf->KeyValid(ev, key);
-
- if ( _fSection != (SectionHandle) kODNULL )
- {
- if ( IsTopDraft(ev, somSelf->GetStorageUnit(ev)->GetDraft(ev)) )
- {
- FSSpec editionFile;
- ODBoolean wasChanged;
-
- OSErr error = ResolveAlias(nil, (**_fSection).alias, &editionFile, &wasChanged);
- THROW_IF_ERROR(error);
-
- if ( IsRegisteredSection(_fSection) == noErr )
- {
- error = UnRegisterSection(_fSection);
- if ( error == noErr )
- somSelf->Release(ev); // RefCount incremented when section was registered
- }
-
- error = DeleteEditionContainerFile(&editionFile);
- THROW_IF_ERROR(error);
-
- ODDisposeHandle((ODHandle) (**_fSection).alias);
- ODDisposeHandle((ODHandle) _fSection);
- _fSection = (SectionHandle) kODNULL;
-
- somSelf->SetLinkDirty(ev);
- }
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLink: UpdateLinkEdition
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkUpdateLinkEdition(ODLink *somSelf, Environment *ev,
- ODLinkKey key)
- {
- ODLinkData *somThis = ODLinkGetData(somSelf);
- ODLinkMethodDebug("ODLink","UpdateLinkEdition");
-
- SOM_TRY
-
- if (_fSection != (SectionHandle) kODNULL)
- {
- ODTime changeTime = somSelf->GetChangeTime(ev);
- if ((TimeStamp) changeTime != (**_fSection).mdDate)
- {
- ODStorageUnit* storageUnit = somSelf->GetStorageUnit(ev);
- ODContainer* container = storageUnit->GetDraft(ev)->GetDocument(ev)->GetContainer(ev);;
- ODFileSpec documentSpec = GetODFileSpecFromContainer(ev, container);
-
- (**_fSection).mdDate = (TimeStamp) changeTime;
- somSelf->WriteLinkEdition(ev, _fSection, &documentSpec, key);
- }
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //------------------------------------------------------------------------------
- // ODLink: GetPlatformValue
- //------------------------------------------------------------------------------
-
- SOM_Scope ODHandle SOMLINK ODLinkGetPlatformValue(ODLink *somSelf, Environment *ev,
- ODPlatformType platformType,
- ODLinkKey key)
- {
- ODLinkData *somThis = ODLinkGetData(somSelf);
- ODLinkMethodDebug("ODLink","GetPlatformValue");
-
- ODHandle dataHandle = (ODHandle) kODNULL;
-
- SOM_TRY
-
- ODULong dataSize;
- ODStorageUnit* contentSU = somSelf->GetContentStorageUnit(ev, key);
- ODValueType isoType = kODNULL;
-
- ODVolatile(isoType);
- ODVolatile(dataHandle);
- TRY
- ODTranslation* translation = somSelf->GetStorageUnit(ev)->GetSession(ev)->GetTranslation(ev);
- isoType = translation->GetISOTypeFromPlatformType(ev, platformType, kODPlatformDataType);
-
- if ( ODSUExistsThenFocus(ev, contentSU, kODPropContents, isoType) )
- {
- dataSize = contentSU->GetSize(ev);
- dataHandle = ODNewHandle(dataSize);
- ODValue dataPtr = ODLockHandle(dataHandle);
- StorageUnitGetValue(contentSU, ev, dataSize, dataPtr);
- ODUnlockHandle(dataHandle);
- }
- CATCH_ALL
- ODDisposeHandle(dataHandle);
- dataHandle = (ODHandle) kODNULL;
- ENDTRY
-
- ODDisposePtr(isoType);
-
- SOM_CATCH_ALL
- dataHandle = kODNULL;
- SOM_ENDTRY
-
- return dataHandle;
- }
-
- //------------------------------------------------------------------------------
- // ODLink: CloneToMemoryContainer
- //------------------------------------------------------------------------------
-
- SOM_Scope ODHandle SOMLINK ODLinkCloneToMemoryContainer(ODLink *somSelf, Environment *ev,
- ODLinkKey key)
- {
- ODLinkData *somThis = ODLinkGetData(somSelf);
- ODLinkMethodDebug("ODLink","CloneToMemoryContainer");
-
- SOM_TRY
-
- ODHandle containerHandle;
- ODContainer* container = (ODContainer*) kODNULL;
- ODDocument* document = (ODDocument*) kODNULL;
- ODDraft* draft = (ODDraft*) kODNULL;
- ODStorageUnit* draftProperties = (ODStorageUnit*) kODNULL;
- ODStorageUnit* contentSU = (ODStorageUnit*) kODNULL;
- ODDraft* myDraft = somSelf->GetStorageUnit(ev)->GetDraft(ev);
- ODSession* session = somSelf->GetStorageUnit(ev)->GetSession(ev);
- ODStorageUnitID rootSUID = 0;
-
- ODVolatile(draft);
- ODVolatile(draftProperties);
- ODVolatile(document);
- ODVolatile(container);
- ODVolatile(containerHandle);
- ODVolatile(myDraft);
-
- contentSU = somSelf->GetContentStorageUnit(ev, key);
-
- // Externalize contentSU to force resolution of promises before the
- // clone into the memory container is begun.
- contentSU->Externalize(ev);
-
- containerHandle = ODNewHandle(0);
- TRY
- container = CreateMemoryContainer(ev, session, containerHandle, kODBentoMemoryContainer);
-
- document = container->AcquireDocument(ev, kODDefaultDocument);
-
- draft = document->AcquireBaseDraft(ev, kODDPExclusiveWrite);
-
- ODDraftKey draftKey = myDraft->BeginClone(ev, draft, kODNULL, kODCloneAll);
- ODVolatile(draftKey);
- TRY
- rootSUID = myDraft->Clone(ev, draftKey, contentSU->GetID(ev), kODNULLID, 0);
-
- if ( ODSUExistsThenFocus(ev, contentSU, kODPropContentFrame, kODWeakStorageUnitRef) )
- {
- ODID contentFrameID = ODGetWeakSURefProp(ev, contentSU, kODPropContentFrame, kODWeakStorageUnitRef);
- myDraft->Clone(ev, draftKey, contentFrameID, kODNULLID, 0);
- }
- CATCH_ALL
- myDraft->AbortClone(ev, draftKey);
- RERAISE;
- ENDTRY
-
- myDraft->EndClone(ev, draftKey);
-
- draftProperties = draft->AcquireDraftProperties(ev);
- ODSetStrongSURefProp(ev, draftProperties, kODPropRootPartSU, kODStrongStorageUnitRef, rootSUID);
- draftProperties->Release(ev);
- draftProperties = kODNULL;
-
- draft->Externalize(ev);
- draft->Release(ev);
- document->Release(ev);
- container->Release(ev);
-
- CATCH_ALL
- ODReleaseObject(ev, draftProperties);
- ODReleaseObject(ev, draft);
- ODReleaseObject(ev, document);
- ODReleaseObject(ev, container);
-
- ODDisposeHandle(containerHandle);
- RERAISE;
- ENDTRY
-
- return containerHandle;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- return (ODHandle) kODNULL;
- }
-
- //------------------------------------------------------------------------------
- // ODLink: WriteLinkEdition
- //------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODLinkWriteLinkEdition(ODLink *somSelf, Environment *ev,
- SectionHandle section,
- ODFileSpec* documentSpec,
- ODLinkKey key)
- {
- ODLinkData *somThis = ODLinkGetData(somSelf);
- ODLinkMethodDebug("ODLink","WriteLinkEdition");
-
- OSErr infoError;
- OSErr openError;
- OSErr writeError = noErr;
- EditionRefNum edRefNum = 0;
- ODHandle dataHandle = (ODHandle) kODNULL;
- ODBoolean successful = kODTrue;
-
- ODVolatile(dataHandle);
- ODVolatile(successful);
-
- SOM_TRY
-
- if ( section == (SectionHandle) kODNULL )
- THROW(kODErrNotExportedLink);
-
- FInfo documentFInfo;
- infoError = FSpGetFInfo((FSSpecPtr) documentSpec, &documentFInfo);
- THROW_IF_ERROR(infoError);
-
- openError = OpenNewEdition(section, documentFInfo.fdCreator, documentSpec, &edRefNum);
- THROW_IF_ERROR(openError);
-
- dataHandle = somSelf->CloneToMemoryContainer(ev, key);
- if ( dataHandle != (ODHandle) kODNULL )
- {
- ODPtr dataPtr = ODLockHandle(dataHandle);
- writeError = WriteEdition(edRefNum, kODScrapTypeODBentoContainer, dataPtr, ODGetHandleSize(dataHandle));
- ODDisposeHandle(dataHandle);
- dataHandle = kODNULL;
- }
- THROW_IF_ERROR(writeError);
-
- // Also write out any text content property (unnecessary for OpenDoc, but allows
- // subscribing by non-OpenDoc applications, and allows the Edition Manager to display
- // content in the GetInfo dialog.
- dataHandle = somSelf->GetPlatformValue(ev, 'TEXT', key);
- if ( dataHandle != (ODHandle) kODNULL )
- {
- ODPtr dataPtr = ODLockHandle(dataHandle);
- writeError = WriteEdition(edRefNum, 'TEXT', dataPtr, ODGetHandleSize(dataHandle));
- ODUnlockHandle(dataHandle);
- ODDisposeHandle(dataHandle);
- dataHandle = kODNULL;
- }
- THROW_IF_ERROR(writeError);
-
- dataHandle = somSelf->GetPlatformValue(ev, 'PICT', key);
- if ( dataHandle != (ODHandle) kODNULL )
- {
- ODPtr dataPtr = ODLockHandle(dataHandle);
- writeError = WriteEdition(edRefNum, 'PICT', dataPtr, ODGetHandleSize(dataHandle));
- ODUnlockHandle(dataHandle);
- ODDisposeHandle(dataHandle);
- dataHandle = kODNULL;
- }
- THROW_IF_ERROR(writeError);
-
-
- SOM_CATCH_ALL
-
- ODDisposeHandle(dataHandle);
- successful = kODFalse;
-
- SOM_ENDTRY;
-
- if ( edRefNum != 0 )
- CloseEdition(edRefNum, successful);
- }
-